
<template>
  <div id="studentdormitorymanage" style= "height:100%;width:100%;padding: 0;background-image: linear-gradient(to right top, #a1d1ff, #c2daff, #dce5ff, #f0f1ff, #ffffff);">
    <div class="searchwrapper">
      <p>姓名</p>
      <el-input
          placeholder="请输入内容"
          prefix-icon="el-icon-search"
          v-model="studentName"
          style="width: 200px;margin-right:20px"
      >
      </el-input>
      <p>学号</p>
      <el-input
          placeholder="请输入内容"
          prefix-icon="el-icon-search"
          v-model="studentAccount"
          style="width: 200px;margin-right: 100px"
      >
      </el-input>
      <el-button style="margin-left: 20px" type="primary" icon="el-icon-search" @click="searchStudentByNameAndAccount">搜索</el-button>
      <div style="width: 500px"></div>
    </div>
    <div id="table" style="margin-left: 50px;margin-right: 50px">
      <el-table
          :data="studentList"
          style="width: 90%">
        <el-table-column
            prop="student.account"
            label="学号">
        </el-table-column>
        <el-table-column
            prop="student.name"
            label="姓名"
            width="90">
        </el-table-column>
        <el-table-column
            prop="student.gender"
            label="性别"
            width="50">
        </el-table-column>
        <el-table-column
            prop="student.nation"
            label="民族"
        width="100">
        </el-table-column>
        <el-table-column
            prop="student.birthplace"
            label="生源地">
        </el-table-column>
        <el-table-column
            prop="areaName"
            label="园区">
        </el-table-column>
        <el-table-column
            prop="buildingName"
            label="楼栋">
        </el-table-column>
        <el-table-column
            prop="roomName"
            label="房间">
        </el-table-column>
      </el-table>
      <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNo"
          :page-sizes="[2,5,10]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import {_searchStudentByNameAndAccount} from '../../../api/super_admin'
import buildingEditDialog from '../components/editComponents/BuildingEditDialog.vue'
import buildingAddDialog from '../components/addComponents/BuildingAddDialog.vue'

export default {
  name: 'StudentDormitoryManage',
  components: {buildingAddDialog, buildingEditDialog},
  created () {
    this.getFirstPage()
  },
  data () {
    return {
      studentList: [{
        student: {
          name: '潘姐红',
          gender: '女',
          nation: '汉族',
          birthplace: '北京市',
          account: 's4656155454'
        },
        roomName: '101A',
        buildingName: '西苑3舍',
        areaName: '江安小区'
      }],
      studentName: '',
      preStudentName: '',
      studentAccount: '',
      preStudentAccount: '',
      total: 0,
      pageNo: 1,
      pageSize: 10
    }
  },
  methods: {
    getFirstPage () {
      const DOT = {
        pageSize: this.pageSize,
        pageNo: 1,
        data: {
          studentName: this.preStudentName,
          studentAccount: this.preStudentAccount
        }
      }
      _searchStudentByNameAndAccount(DOT).then(res => {
        if (res.status) {
          this.studentList = res.data
          this.pageNo = 1
        } else {
          this.$message({
            message: res.message,
            type: 'error'
          })
        }
      })
    },
    getStudent () {
      const DOT = {
        pageSize: this.pageSize,
        pageNo: this.pageNo,
        data: {
          studentName: this.preStudentName,
          studentAccount: this.preStudentAccount
        }
      }
      _searchStudentByNameAndAccount(DOT).then(res => {
        if (res.status) {
          this.studentList = res.data
        } else {
          this.$message({
            message: res.message,
            type: 'error'
          })
        }
      })
    },
    searchStudentByNameAndAccount () {
      this.preStudentName = this.studentName
      this.preStudentAccount = this.studentAccount
      this.getFirstPage()
    },
    handleSizeChange (value) {
      this.pageSize = value
      this.getFirstPage()
    },
    handleCurrentChange (value) {
      this.pageNo = value
      this.getStudent()
    }
  }
}
</script>

<style scoped>
.searchwrapper {
  margin-top: 10px;
  display: flex; /* 使用 Flexbox 布局 */
  align-items: center; /* 垂直居中对齐 */
}
.searchwrapper p {
  margin-left: 200px;
  margin-right: 10px; /* 调整 p 标签与 el-input 之间的间距 */
  font-weight: bold; /* 可选：设置 p 标签的字体加粗 */
}

.searchwrapper .el-input {
  flex: 1; /* el-input 自动填充剩余空间 */
}
</style>
